﻿package mortal.game.view.guild.cellrender
{
    import Message.DB.Tables.*;
    import Message.Game.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.common.global.*;
    import mortal.game.manager.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.item.*;
    import mortal.game.view.guild.otherpanel.*;

    public class GuildShopCellRenderer extends GCellRenderer
    {
        private var _tGuildShopItem:TGuildShopSell;
        private var _sguildShopItem:SGuildShopItem;
        private var _shopItem:BaseItem;
        private var _itemName:GTextFiled;
        private var _contributions:GTextFiled;
        private var _leftNum:GTextFiled;
        private var _limitNum:GTextFiled;

        public function GuildShopCellRenderer()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this.pushUIToDisposeVec(UIFactory.bg(0, 0, 149, 55, this, ImagesConst.InputDisablBg));
            this.pushUIToDisposeVec(UIFactory.bg(216, 6, 95, 7, this, ImagesConst.ComboBg));
            this.pushUIToDisposeVec(UIFactory.bg(216, 27, 95, 7, this, ImagesConst.ComboBg));
            this._shopItem = UICompomentPool.getUICompoment(BaseItem);
            this._shopItem.x = 5;
            this._shopItem.y = 7;
            this._shopItem.setItemStyle(ItemStyleConst.Small, ImagesConst.PackItemBg, 2, 2);
            this._shopItem.mouseChildren = false;
            this._shopItem.doubleClickEnabled = true;
            this._shopItem.configEventListener(MouseEvent.ROLL_OVER, this.showCursor);
            this._shopItem.configEventListener(MouseEvent.ROLL_OUT, this.hidCursor);
            this.addChild(this._shopItem);
            this._itemName = UIFactory.gTextField("100", 55, 5, 120, 20, this, null, true);
            this._itemName.mouseEnabled = false;
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(30091), 55, 26, 100, 20, this));
            this._contributions = UIFactory.gTextField("10", 95, 26, 120, 20, this);
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(30092), 155, 5, 100, 20, this, GlobalStyle.textFormatItemGreen));
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(30093), 155, 26, 100, 20, this, GlobalStyle.textFormatHuang));
            this._leftNum = UIFactory.gTextField("10", 188, 5, 120, 20, this, GlobalStyle.textFormatItemGreen.right());
            this._limitNum = UIFactory.gTextField("10", 188, 26, 120, 20, this, GlobalStyle.textFormatHuang.right());
            this.configEventListener(MouseEvent.CLICK, this.clickHandler);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._shopItem.dispose(param1);
            this._shopItem = null;
            this._itemName.dispose(param1);
            this._shopItem = null;
            this._contributions.dispose(param1);
            this._contributions = null;
            this._leftNum.dispose(param1);
            this._leftNum = null;
            this._limitNum.dispose(param1);
            this._limitNum = null;
            return;
        }// end function

        private function showCursor(event:MouseEvent) : void
        {
            CursorManager.currentCurSorType = CursorManager.BUY;
            CursorManager.showCursor(CursorManager.BUY);
            return;
        }// end function

        private function hidCursor(event:MouseEvent) : void
        {
            CursorManager.currentCurSorType = CursorManager.Arrow;
            CursorManager.showCursor(CursorManager.Arrow);
            return;
        }// end function

        override public function set data(param1:Object) : void
        {
            this._sguildShopItem = param1.sguildShopItem as SGuildShopItem;
            this._tGuildShopItem = param1.tGuildShopItem as TGuildShopSell;
            this._shopItem.itemData = new ItemData(this._tGuildShopItem.itemCode);
            this._itemName.htmlText = ItemsUtil.getItemName(this._shopItem.itemData);
            this._contributions.text = this._sguildShopItem.price.toString();
            this._leftNum.text = this._sguildShopItem.leftAmount.toString();
            this._limitNum.text = this._sguildShopItem.buyLimit.toString();
            return;
        }// end function

        private function clickHandler(event:MouseEvent) : void
        {
            GuildShopBuyItemWin.instance.showWin(this._sguildShopItem);
            return;
        }// end function

    }
}
